package com.ljx.date.date01;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/7 9:33
 * @Version 1.0
 */
public class LocalDateTimeFormatParse {
	public static void main(String[] args) {
		/**
		 * 把日期转换成字符串和字符串转换成日期类型
		 *
		 *DateTimeFormat可以进行日期和字符串的转化
		 */
		//1 把日期转换成字符串类型
		LocalDateTime now = LocalDateTime.now();
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		String format = formatter.format(now);
		System.out.println(format);

		//2将字符串转换成日期类型
		 String date1="2022-05-12";
		 LocalDate parse = LocalDate.parse(date1, formatter);
		 System.out.println(parse);


		 //将字符串转换成日期时间类
		DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		String dateTime="2022-12-12 12:12:12";
		LocalDateTime parse1 = LocalDateTime.parse(dateTime,formatter1);
		System.out.println(parse1);

	}
}
